package com.huangj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.huangj.entity.HomeEntity;
import com.huangj.pro2_h2pop.R;

import java.util.List;

/**
 * Created by HuangJ on 2016/10/3.15:02
 */
public class HomeGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<HomeEntity.DataBean.DestinationsBean> gvDatas;

    public HomeGridViewAdapter(Context context,List<HomeEntity.DataBean.DestinationsBean> gvDatas) {
        this.context = context;
        this.gvDatas = gvDatas;
//        Log.d("print", "HomeGridViewAdapter: "+gvDatas.get(0).getName());
    }

    @Override
    public int getCount() {
        return gvDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return gvDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView != null){
            viewHolder = (ViewHolder) convertView.getTag();
        }else {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_homegridview,null);
            viewHolder.iv_lv = (ImageView) convertView.findViewById(R.id.iv_lv);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_nameen = (TextView) convertView.findViewById(R.id.tv_nameen);
            convertView.setTag(viewHolder);
        }
//        Log.d("print", "getView: 运行到此");
            viewHolder.tv_name.setText(gvDatas.get(position).getName());
//        Log.d("print", "getView: "+gvDatas.get(position).getName());
            viewHolder.tv_nameen.setText(gvDatas.get(position).getName_en());
            Glide.with(context).load(gvDatas.get(position).getPhoto_url())
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.drawable.icon_empty)
                    .crossFade()
                    .into(viewHolder.iv_lv);

        return convertView;
    }
    class ViewHolder{
        ImageView iv_lv;
        TextView tv_name,tv_nameen;
    }
}
